package cn.maidouya.basic.service.impl;

import cn.maidouya.basic.mapper.BaseMapper;
import cn.maidouya.basic.query.BaseQuery;
import cn.maidouya.basic.service.BaseService;
import cn.maidouya.basic.util.PageList;
import cn.maidouya.product.query.ProductQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
// 传播事件
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }
    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public T loadById(Long id) {
        T one = (T) baseMapper.loadById(id);
        return one;
    }

    @Override
    public List<T> loadAll() {
        List<T> list = baseMapper.loadAll();
        return list;
    }

    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {
        Integer count = baseMapper.queryCount(baseQuery);
        if (count <= 0){
            return new PageList<T>();
        }
        List<T> list = baseMapper.queryData(baseQuery);
        PageList<T> pageList = new PageList<T>(count, list);
        return pageList;
    }







}